/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.coreGenerator.base.entitygen.determination;

import com.inspur.edp.caf.generator.BaseGenerator;
import com.inspur.edp.caf.generator.composite.CompositeGenerator;
import com.inspur.edp.caf.generator.composite.CompositeGeneratorContext;
import com.inspur.edp.cef.designtime.api.IGspCommonField;
import com.inspur.edp.cef.designtime.api.operation.CommonDetermination;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.DataTypeImpContext;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.determination.AfterCreate.AfterCreateDtmGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.determination.AfterModify.AfterModifyDtmGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.determination.BeforeSave.BeforeSaveDtmGenerator;

public abstract class DataTypeDtmsGenerator extends CompositeGenerator {
  protected DataTypeImpContext  dataTypeImplGenCtx;

  protected DataTypeDtmsGenerator(DataTypeImpContext dataTypeImplGenCtx) {
    super();
    this.dataTypeImplGenCtx = dataTypeImplGenCtx;
  }

  @Override
  protected CompositeGeneratorContext createCompositeContext() {
    DataTypeDtmsGenCtx ctx = createDtmsGenCtx();
    dataTypeImplGenCtx.setDtmsGenCtx(ctx);
    return ctx;
  }


  // keyword:
  // ORIGINAL LINE: protected new DataTypeDtmsGenCtx getContext() { return
  // (DataTypeDtmsGenCtx)super.getContext(); }
  @Override
  protected DataTypeDtmsGenCtx getContext() {
    return (DataTypeDtmsGenCtx) super.getContext();
  }

  protected DataTypeDtmsGenCtx createDtmsGenCtx() {
    return new DataTypeDtmsGenCtx(this.dataTypeImplGenCtx);
  }

  @Override
  protected final java.util.ArrayList<BaseGenerator> createCompositeItemGenerators() {
    java.util.ArrayList<BaseGenerator> list = new java.util.ArrayList<BaseGenerator>();
    list.addAll(getAfterCreateDtmGens());
    list.addAll(getAfterModifyDtmGens());
    list.addAll(getBeforeSaveDtmGens());
    getNestedDtmGens(list);
    java.util.ArrayList<BaseGenerator> extend = getExtendCompositeItemGenerators();
    if (extend != null) {
      list.addAll(extend);
    }
    return list;
  }


  /// #region NestedDtmGens
  private void getNestedDtmGens(java.util.ArrayList<BaseGenerator> list) {
    if (getContext().getDataType().getContainElements() == null) {
      return;
    }

    for (IGspCommonField item : getContext().getDataType().getContainElements()) {
      if (!item.getIsUdt()) {
        continue;
      }
    }
  }

  //endregion

  private java.util.ArrayList<AfterCreateDtmGenerator> getAfterCreateDtmGens() {
    java.util.ArrayList<AfterCreateDtmGenerator> list =
        new java.util.ArrayList<AfterCreateDtmGenerator>();
    if (getContext().getDtmAfterCreate()== null) {
      return list;
    }
    for (CommonDetermination item : getContext().getDtmAfterCreate()) {
      list.add(getAfterCreateDtmGenerator(item));
    }
    return list;
  }

  protected abstract AfterCreateDtmGenerator getAfterCreateDtmGenerator(CommonDetermination dtm);

  private java.util.ArrayList<AfterModifyDtmGenerator> getAfterModifyDtmGens() {
    java.util.ArrayList<AfterModifyDtmGenerator> list =
        new java.util.ArrayList<AfterModifyDtmGenerator>();
    if (getContext().getDtmAfterModify()== null) {
      return list;
    }

    for (CommonDetermination item : getContext().getDtmAfterModify()) {
      list.add(getAfterModifyDtmGenerator(item));
    }
    return list;
  }

  protected abstract AfterModifyDtmGenerator getAfterModifyDtmGenerator(CommonDetermination dtm);

  private java.util.ArrayList<BeforeSaveDtmGenerator> getBeforeSaveDtmGens() {
    java.util.ArrayList<BeforeSaveDtmGenerator> list =
        new java.util.ArrayList<BeforeSaveDtmGenerator>();
    if (getContext().getDtmBeforeSave() == null) {
      return list;
    }

    for (CommonDetermination item : getContext().getDtmBeforeSave()) {
      list.add(getBeforeSaveDtmGenerator(item));
    }
    return list;
  }

  protected abstract BeforeSaveDtmGenerator getBeforeSaveDtmGenerator(CommonDetermination dtm);

  protected java.util.ArrayList<BaseGenerator> getExtendCompositeItemGenerators() {
    return null;
  }
}
